/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View.components;

import Algorithm.Algoritmo;
import Model.Usuario;
import Principals.Main;
import View.seguridad.*;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import static javax.swing.WindowConstants.HIDE_ON_CLOSE;

/**
 *
 * @author walter
 */
public final class IndexOlvidoContrasenha extends JFrame {

    private JDesktopPane container;
    private JDesktopPane internal;
    JInternalFrame accion;
    private JMenuBar mbMenu;
    private JMenu mnCuenta;
    private JMenuItem mniSalirSistema;
    private JMenuItem mniCambiarContrasenha;
    private Usuario user;

    public IndexOlvidoContrasenha(JDesktopPane panel) {
        initComponents();
        changeDesktopPane(panel);
    }

    public IndexOlvidoContrasenha(Usuario usr) {
        initComponents();
        user = usr;
        changeDesktopPane(new Frm_CambiarContrasenhaPorOlvido(user));
    }

    public void initComponents() {
        Main.genetico = new Algoritmo();

        // container 
        container = new JDesktopPane();
        internal = new JDesktopPane();

        // Barra menu
        mbMenu = new JMenuBar();

        // MENU CUENTA
        mnCuenta = new JMenu();
        mniSalirSistema = new JMenuItem();
        mniCambiarContrasenha = new JMenuItem();

        mnCuenta.setText("Mi cuenta"); // <--------------------------------------------- MENU CUENTA
        mniCambiarContrasenha.setText("Cambiar contraseña");
        mniCambiarContrasenha.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniCambiarContrasenhaActionPerformed(evt);
            }
        });
        mnCuenta.add(mniCambiarContrasenha);

        mniSalirSistema.setText("Salir del sistema");
        mniSalirSistema.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniSalirSistemaActionPerformed(evt);
            }
        });
        mnCuenta.add(mniSalirSistema);



        mbMenu.add(mnCuenta);


        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("DP1");

        setJMenuBar(mbMenu);
        setResizable(false);

        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        setSize(d.width / 2, d.height / 2);
        this.setLocation(0, 0);
//        setSize(d.width, d.height);
//        this.setLocation((int) d.getWidth() / 2 - (int) this.getPreferredSize().getWidth() / 2,
//                (int) d.getHeight() / 8 - (int) this.getPreferredSize().getHeight() / 8);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        this.setUndecorated(true);
    }

    // <editor-fold defaultstate="collapsed" desc="Eventos">
    private void mniSalirSistemaActionPerformed(java.awt.event.ActionEvent evt) {
        System.exit(0);
    }

    private void mniCambiarContrasenhaActionPerformed(java.awt.event.ActionEvent evt) {
        changeDesktopPane(new Frm_CambiarContrasenhaPorOlvido(user));
    }

    // </editor-fold>
    public void addContentPane(JPanel panel) {
        //content panes must be opaque
        panel.setOpaque(true);
        this.getContentPane().add(panel);
        pack();
    }

    public void changeContentPane(JPanel panel) {
        this.getContentPane().removeAll();
        // Pass the frame f reference only into MainDisplay, it doesn't actually do anything apart from allowing a class to add a JMenuBar on the JFrame.
        this.getContentPane().invalidate();
        this.getContentPane().validate();
        this.getContentPane().repaint();
        // this.remove(this.getContentPane()) ;
        this.addContentPane(panel);
        pack();
    }

    public void changeDesktopPane(JDesktopPane panel) {
        if (panel.getClass().toString().equals("class View.components.JFrame")) {
            try {
                this.getContentPane().removeAll();
                this.getContentPane().invalidate();
                this.getContentPane().validate();
                this.getContentPane().repaint();

                panel.setOpaque(true);
                this.container = panel;

                this.getContentPane().add(panel);

                pack();

                Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                setSize(d.width, d.height);
            } catch (Exception e) {
            }
        } else {
            this.container = panel;
            internal = new JDesktopPane();
            internal.setSize(this.getWidth(), this.getHeight());
            this.getContentPane().removeAll();
            this.getContentPane().add(internal);
            this.getContentPane().invalidate();
            this.getContentPane().validate();
            this.getContentPane().repaint();

            accion = new JInternalFrame();
            internal.add(accion);
            accion.setDoubleBuffered(true);
            accion.add(panel);
            accion.pack();
            accion.setDefaultCloseOperation(HIDE_ON_CLOSE);
            accion.setLocation((this.getWidth() - panel.getWidth()) / 2, (this.getHeight() - panel.getHeight()) / 4);
            accion.setVisible(true);

            pack();

            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            setSize(d.width, d.height);
        }
    }

    public JDesktopPane getContainer() {
        return container;
    }
}
